package com.job.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.job.common.ResponseResult;
import com.job.common.enums.ResultCodeEnum;
import com.job.common.exception.ParameterIsNullException;
import com.job.controller.req.RecruitAddVO;
import com.job.controller.req.RecruitStudentReqVO;
import com.job.controller.resp.RecruitVO;
import com.job.pojo.vo.StudentVO;
import com.job.service.RecruitService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jetbrains.annotations.NotNull;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@Api("招聘信息管理")
@RequestMapping("/recruit")
public class RecruitController {

    @Resource
    private RecruitService recruitService;

    @ApiOperation("发布岗位招聘")
    @PostMapping("/add")
    public ResponseResult<ResultCodeEnum> recruitAdd(@Validated @RequestBody RecruitAddVO recruitAddVO)
            throws ParameterIsNullException {
        return recruitService.recruitAdd(recruitAddVO);
    }

    @ApiOperation("删除岗位招聘")
    @GetMapping("/delete")
    public ResponseResult<ResultCodeEnum> recruitDelete(@NotNull String positionId){
        return recruitService.recruitDelete(Integer.valueOf(positionId));
    }

    @ApiOperation("修改招聘岗位")
    @PostMapping("/update")
    public ResponseResult<ResultCodeEnum> recruitUpdate(@Validated @RequestBody RecruitAddVO recruitAddVO){
        return recruitService.recruitUpdate(recruitAddVO);
    }

    @ApiOperation("查看自己发布的岗位")
    @GetMapping("/query")
    public ResponseResult<IPage<Map<String,Object>>> recruitQuery(String id) throws ParameterIsNullException {
        return recruitService.recruitQuery(id);
    }

    @ApiOperation("查看自己发布的岗位")
    @GetMapping("/mate/query/{id}")
    public ResponseResult<List<RecruitVO>> recruitMateQuery(@PathVariable("id") String id) throws ParameterIsNullException {
        return recruitService.mateRecruitQuery(id);
    }

    @ApiOperation("查看学生信息")
    @GetMapping("/list")
    public ResponseResult<Page<StudentVO>> studentList(@Validated  RecruitStudentReqVO recruitStudentVO){
        return recruitService.studentList(recruitStudentVO);
    }
}
